home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / util / manip / fn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  2.3 KB  |  82 lines

  1. #include "all.h"
  2. #include "eval.h"
  3.  
  4.  
  5. /*------------------------------------------------------------------*/
  6. /*      Find the function callped *cp, and return it's number       */
  7. /*------------------------------------------------------------------*/
  8.  
  9. /* You can add a function, you MUST place it in alphabetical order  */
  10. /* and give it the next unused index number                */
  11.  
  12. /* ret = Type of returned value,  1=number, 2=string */
  13. /* np = number of paramters expected */
  14. /* Parameters p0...p4  ==  1=number, 2=string, 0=none (e.g. height()) .  */
  15.  
  16. #define NKEYS (sizeof keywfn / sizeof(struct keyw))
  17. struct keyw { char *word; int index; int ret,np,p[5]; } keywfn[] = {
  18.         /*         r  np p1p2p3p4p5 */
  19.         " ",0        ,1 ,0 ,0,0,0,0,0
  20.         ,"+",f_plus    ,1 ,0 ,0,0,0,0,0
  21.         ,"-",f_minus    ,1 ,0 ,0,0,0,0,0
  22.         ,"ABS",f_abs    ,1 ,1 ,1,0,0,0,0
  23.         ,"ATN",f_atn    ,1 ,1 ,1,0,0,0,0
  24.         ,"CELL",f_cell    ,1 ,2 ,1,1,0,0,0
  25.         ,"COS",f_cos    ,1 ,1 ,1,0,0,0,0
  26.         ,"DATE$",f_date    ,2 ,0 ,0,0,0,0,0
  27.         ,"EXP",f_exp    ,1 ,1 ,1,0,0,0,0
  28.         ,"FIX",f_fix    ,1 ,1 ,1,0,0,0,0
  29.         ,"INT",f_int    ,1 ,1 ,1,0,0,0,0
  30.         ,"LEFT$",f_left    ,2 ,2 ,2,1,0,0,0
  31.         ,"LEN",f_len    ,1 ,1 ,2,0,0,0,0
  32.         ,"LOG",f_log    ,1 ,1 ,1,0,0,0,0
  33.         ,"LOG10",f_log10    ,1 ,1 ,1,0,0,0,0
  34.         ,"MISS",f_miss    ,1 ,2 ,1,1,0,0,0
  35.         ,"NOT",f_not    ,1 ,1 ,1,0,0,0,0
  36.         ,"NUM$",f_num    ,2 ,1 ,1,0,0,0,0
  37.         ,"NUM1$",f_num1    ,2 ,1 ,1,0,0,0,0
  38.         ,"POS",f_pos    ,1 ,2 ,2,1,0,0,0
  39.         ,"RIGHT$",f_right    ,2 ,2 ,2,1,0,0,0
  40.         ,"RND",f_rnd    ,1 ,1 ,1,0,0,0,0
  41.         ,"SEG$",f_seg    ,2 ,3 ,2,1,1,0,0
  42.         ,"SGN",f_sgn    ,1 ,1 ,1,0,0,0,0
  43.         ,"SIN",f_sin    ,1 ,1 ,1,0,0,0,0
  44.         ,"SQR",f_sqr    ,1 ,1 ,1,0,0,0,0
  45.         ,"SQRT",f_sqrt    ,1 ,1 ,1,0,0,0,0
  46.         ,"TAN",f_tan    ,1 ,1 ,1,0,0,0,0
  47.         ,"TIME$",f_time    ,2 ,0 ,0,0,0,0,0
  48.         ,"VAL",f_val    ,1 ,1 ,2,0,0,0,0
  49. } ;
  50.  
  51. int binsearch(char *word, struct keyw tab[], int n);
  52.  
  53. find_un(char *cp, int *idx,int *ret,int *np,int **plist)
  54. {
  55.     int i;
  56.     i = binsearch(cp,keywfn,NKEYS);
  57.     *idx = keywfn[i].index;
  58.     *ret = keywfn[i].ret;
  59.     *np =  keywfn[i].np;
  60.     *plist = &keywfn[i].p[0];
  61. }
  62.  
  63. /*------------------------------------------------------------------*/
  64. /* Simple binary search                         */
  65. /*------------------------------------------------------------------*/
  66. binsearch(char *word, struct keyw tab[], int n)
  67. {
  68.     int cond,low,high,mid;
  69.     low = 0;
  70.     high = n-1;
  71.     while (low <= high) {
  72.         mid = (low+high) / 2;
  73.         if ((cond = strcmp(word,tab[mid].word)) < 0)
  74.             high = mid - 1;
  75.         else if (cond > 0)
  76.             low = mid + 1;
  77.         else
  78.             return mid;
  79.     }
  80.     return 0;
  81. }
  82.